#include <cstdio>
#include <vector>
#include <iostream>

using namespace std; 

struct person_s {
	int outter; 
	string career; 
}; 

struct inst_s {
	int right; 
	int s; 
}; 

vector <person_s> ps; 
vector <inst_s>	inst; 

int n, m; 

int dirs[2][2] = {
	{-1, 1}, 
	{1, -1}
}; 

int main()
{
	int i, d, c=0; 
	//freopen("p1563_1.in", "r", stdin); 
	cin>>n>>m; 
	for (i=0; i<n; i++) {
		person_s p; 
		cin>>p.outter>>p.career; 
		ps.push_back(p); 
	}
	for (i=0; i<m; i++) {
		inst_s t; 
		cin>>t.right>>t.s; 
		inst.push_back(t); 
	}
	for (i=0; i<m; i++) {
		inst_s &t = inst[i]; 
		person_s &p = ps[c]; 
		d = dirs[p.outter][t.right]; 
		c += d*t.s; 
		while(c<0) {
			c+=ps.size(); 
		}
		while(c>=(int)ps.size()) {
			c-=ps.size(); 
		}
	}
	cout<<ps[c].career<<"\n"; 
	return 0; 
}

